import { getAreaObj, uploadType } from '@/utils/util'
import bus from '@/utils/eventbus'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '巡查类型',
			prop: 'inspectionType',
			type: 'select',
			dicData: [
				{
					label: '白天',
					value: '1',
				},
				{
					label: '夜间',
					value: '2',
				},
			],
			rules: [{ required: true, message: '请选择巡查类型' }],
			span: 12,
		},
		{
			label: '巡查日期',
			prop: 'inspectionDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			rules: [{ required: true, message: '请选择巡查日期' }],
			span: 12,
		},
		{
			label: '巡查人',
			prop: 'staffId',
			propName: 'staffName',
			type: 'autoSelect',
			api: 'getSecurityUserPage',
			filterKey: 'userId',
			filterLabel: 'realName',
			multiple: false,
			placeholder: '请输入名称查询选择巡查人',
			paramsObj: {
				// roleName: '安全员',
			},
			span: 12,
		},
		{
			label: '巡查结果',
			prop: 'isPatrol',
			type: 'select',
			span: 12,
			rules: [{ required: true, message: '请选择巡查结果' }],
			dicData: [
				{
					label: '正常',
					value: 1,
				},
				{
					label: '异常',
					value: 2,
				},
			],
		},

		{
			label: '巡查图片',
			prop: 'inspectionPic',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 16,
		},
		{
			label: '签字照片',
			tip: '',
			prop: 'signaturePic',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 8,
		},
		{
			label: '巡查内容',
			prop: 'inspectionContent',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'label',
			code: 'INSPECTION_CONTENT',
			span: 12,
			multiple: true,
		},
		{
			label: '问题描述',
			prop: 'description',
			type: 'textarea',
			maxlength: '500',
			showWordLimit: true,
			autosize: {
				minRows: 1,
			},
			span: 12,
		},
	],
}

export const detailConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		...formConfig.column,
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '处理信息',
			span: 24,
		},
		{
			label: '处理备注',
			prop: 'handleNote',
			type: 'textarea',
			maxlength: '500',
			showWordLimit: true,
			autosize: {
				minRows: 1,
			},
			span: 24,
		},
		{
			label: '处理图片',
			prop: 'handlePic',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 12,
		},
		{
			label: '签字照片',
			tip: '',
			prop: 'handleSignaturePic',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 6,
		},
		{
			label: '签名',
			prop: 'handleSignatureText',
			type: 'input',
			span: 6,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '所属单位',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '巡查类型',
			prop: 'inspectionType',
			type: 'select',
			dicData: [
				{
					label: '白天',
					value: '1',
				},
				{
					label: '夜间',
					value: '2',
				},
			],
			span: 8,
		},
		{
			label: '巡查日期',
			prop: 'inspectionDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '巡查内容',
			prop: 'inspectionContent',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'label',
			code: 'INSPECTION_CONTENT',
			span: 8,
			multiple: true,
		},
		{
			label: '巡查结果',
			prop: 'isPatrol',
			type: 'select',
			span: 8,
			dicData: [
				{
					label: '正常',
					value: 1,
				},
				{
					label: '异常',
					value: 2,
				},
			],
		},
		{
			label: '处理结果',
			prop: 'isHandle',
			type: 'select',
			span: 8,
			dicData: [
				{
					label: '未处理',
					value: 1,
				},
				{
					label: '已处理',
					value: 2,
				},
			],
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '所属单位', prop: 'organizationName' },
		{
			label: '巡查类型',
			prop: 'inspectionType',
			custome: 'tag',
			dicData: [
				{
					label: '白天',
					value: 1,
				},
				{
					label: '夜间',
					value: 2,
				},
			],
		},
		{ label: '巡查日期', prop: 'inspectionDate' },
		{
			label: '巡查内容',
			prop: 'inspectionContent',
			code: 'INSPECTION_CONTENT',
		},
		{ label: '巡查人', prop: 'staffName' },
		{
			label: '巡查结果',
			prop: 'isPatrol',
			custome: 'tag',
			dicData: [
				{
					label: '正常',
					value: 1,
					type: 'success',
				},
				{
					label: '异常',
					value: 2,
					type: 'danger',
				},
			],
		},
		{
			label: '处理结果',
			prop: 'isHandleStatus',
			custome: 'tag',
			dicData: [
				{
					label: '未处理',
					value: 1,
					type: 'danger',
				},
				{
					label: '已处理',
					value: 2,
					type: 'success',
				},
				{
					label: '无需处理',
					value: 3,
					type: 'info',
				},
			],
		},
		{ label: '巡查照片', prop: 'inspectionPic', custome: 'file' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_ffDailyFireInspection_page',
	add: 'view_ffDailyFireInspection_add',
	edit: 'view_ffDailyFireInspection_edit',
	delete: 'view_ffDailyFireInspection_del',
  detail:'view_ffDailyFireInspection_view',
	export: 'view_ffDailyFireInspection_export',
	authArea: 'authArea',
}
export const baseConfig = {
	pageName: '日常防火巡查',
	dictcodes: ['INSPECTION_CONTENT'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'inspectionDate',
	exportMqTopic: '/ning/export/',
	loadOrgInfo: true,
	api,
	auth: {
		...api,
		mulitSet: 'mulitSet',
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '处理',
			type: 'primary',
			operate: 'HandleForm',
			auth: api.edit,
			condition: '(row)=>row.isHandleStatus ==1',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: api.detail,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig,
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: (arr: any) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					if (item.isPatrol == 1) {
						item.isHandleStatus = 3
					} else {
						item.isHandleStatus = item.isHandle
					}
					return item
				})
			)
		})
	},
}
